<template lang="html">
  <div>
    <div class="search">
        <div class="input">
            <p><label>流程名称：</label><el-input placeholder="请输入内容" v-model="pageData.name"></el-input></p>
             <p><el-button type="primary" class="se" style="margin-left:10px;" @click="search">搜索</el-button></p>
        </div>
    </div>
    <div class="add">
       <el-button type="primary" @click="add">新增流程</el-button>
    </div>
    <tableVue :list="list" :state="false" v-loading="pageData.loading" :total="total" @sizeChange="handSize">
        <slot>
          <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  @click="add(scope.row)">编辑
                </el-button>
                <el-button
                  size="mini"
                  type="danger"
                  class="del"
                  @click="del(scope.row,2)">删除</el-button>
              </template>
          </el-table-column>
        </slot>
    </tableVue>
  </div>
</template>

<script>
  import tableVue from '@/components/alltable.vue'
  import {
    flowList,
    delFlow
  } from "@/api/shoppingCentre/shoppingCentre";
  export default {
    components : {
      tableVue,
    },
    data () {
      return {
        list : {
          thead : [
            {label:'报告名称',prop:"procedureName",rowspan:1},
            {label:'报告描述',prop:"procedureDesc",rowspan:1},
            {label:'创建时间',prop:"gmtCreate",rowspan:1},
          ],
          tbody : []
        },
        pageData : {
          name :'',
          loading : false
        },
        total :0
      }
    },
    mounted () {
      this.getflowList();
    },
    methods : {
      getflowList (data) {//科目列表
        this.pageData.loading = true;
          flowList(data).then(res=>{
            if (res.data.code == 'OK') {
              this.pageData.loading = false;
              this.total = res.data.data.total;
              this.list.tbody = res.data.data.records.map(item=>{
                 item.gmtCreate = this.switchTime(item.gmtCreate)
                 item.gmtUpdate = this.switchTime(item.gmtUpdate)
                 return item;
              });
            } else {
               setTimeout(()=>{
                 this.pageData.loading = false;
               },2000)
            }
          })
      },
      add (item) {
        this.$router.push({
          name :'addqualityFlow',
          query : {
            id : item.procedureId
          }
        })
      },
      search () {
        var data = {
          procedureName : this.pageData.name
        }
        this.getflowList(data);
      },
      handSize (val) {
        var data = {
          procedureName : this.pageData.name,
          current : val
        }
        this.getflowList(data);
      },
      del (item) {
        this.delMessage(()=>{
          var id = [];
          id.push(item.procedureId)
          delFlow(id).then(res=>{
            if (res.data.code == 'OK') {
              this.$message.success('删除成功');
                this.getflowList();
            } else {
              this.$message.error(res.data.message);
            }
          })
        })
      },
    }
  }
</script>

<style scoped>
  @import "../../../../styles/common.css";
</style>
